package LC;

public class LC29 {
    public int maxProfit (int[] prices) {
        // write code here
        int ans = 0;
        for (int i = 0; i < prices.length - 1; i++) {
            ans += Math.max(prices[i + 1] - prices[i], 0);
        }
        return ans;
    }
}

class Test{
    public static void main(String[] args) {
        LC29 lc29 = new LC29();
        System.out.println(lc29.maxProfit(new int[]{2,1,4}));
    }
}